package com.example.asus.a1127;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.GridView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MainActivity extends AppCompatActivity {
    private GridView gridview;
    private String strs[]={"六脉神剑","葵花宝典","倚天屠龙","独孤九剑","华山剑法 ","凌波微步","白鹤亮翅","如来神掌","移花接木"};
    private int img[]={
            R.mipmap.eee,R.mipmap.yyy1,
            R.mipmap.eee,R.mipmap.eee,
            R.mipmap.eee,R.mipmap.eee,
            R.mipmap.eee,R.mipmap.eee,R.mipmap.eee};
    private SimpleAdapter simple;
    private List<Map<String, Object>> list=new ArrayList<Map<String,Object>>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getData();
        initView();
    }
    private void initView() {
        gridview =(GridView) findViewById(R.id.gridview);
        String [] from ={"imag","text"};
        int [] to = {R.id.iii,R.id.uuu};
        simple = new SimpleAdapter(this, list, R.layout.item, from, to);
        gridview.setAdapter(simple);
    }
    public List<Map<String, Object>> getData(){
        for(int i=0;i<img.length;i++){
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("imag", img[i]);
            map.put("text", strs[i]);
            list.add(map);
        }
        return list;
    }
}
